chinese_zodiac = '猴鸡狗猪鼠牛虎兔龙蛇马羊'
# u 表示UNICODE
zodiac_name = (u'摩羯座', u'水瓶座', u'双鱼座', u'白羊座', u'金牛座', u'双子座', u'巨蟹座', u'狮子座', u'处女座', u'天秤座', u'天蝎座', u'射手座')
# 定义一个嵌套元组, 12-23到01-20是摩羯座
zodiac_days = ((1, 20), (2, 19), (3, 21), (4, 21), (5, 21), (6, 22), (7, 23), (8, 23), (9, 23), (10, 23), (11, 23), (12, 23))

# #定义一个元组变量
# (month, day) = (11, 5)
# zodiac_day = filter(lambda x: x<=(month, day), zodiac_days)
# ##print(list(zodiac_day))    # 不屏蔽后面结果输出不正确，list只能调用一次，第二次为空
# zodiac_len = len(list(zodiac_day)) % 12
# print(zodiac_name[zodiac_len])


# int_y = int(input('please input year:'))
# int_m = int(input('please input month:'))
# int_d = int(input('please input day:'))

# size = range(len(zodiac_days))
# for zd in size:
#     if (int_m, int_d) < zodiac_days[zd]:
#         print(zodiac_name[zd])
#         break
#     elif int_m == 12 and int_d >= 23:
#         print(zodiac_name[0])
#         break

#
# size = len(zodiac_days)
# i = 0
# while i < size:
#     if (int_m, int_d) < zodiac_days[i]:
#         print(zodiac_name[i])
#         break
#     elif int_m == 12 and int_d >= 23:
#         print(zodiac_name[0])
#         break
#     i += 1


# cz_num = {}
# for i in chinese_zodiac:
#     cz_num[i] = 0
#
# z_num = {}
# for i in zodiac_name:
#     z_num[i] = 0

# 列表推导式
multiples = [i for i in range(30) if i % 3 is 0]
print(multiples)        # [0, 3, 6, 9, 12, 15, 18, 21, 24, 27]


def squared(x):
    return x*x


multiples = [squared(i) for i in range(30) if i % 3 is 0]
print(multiples)        # [0, 9, 36, 81, 144, 225, 324, 441, 576, 729]

# 字典推导式
case = {'a': 10, 'b': 34}
case_map = {v: k for k, v in case.items()}
print(case_map)         # {34: 'b', 10: 'a'}

# 集合推导式
squared = {x**3 for x in [1, 2, 3, 4]}  # **
print(squared)          # {8, 1, 27, 64}
# 排序之后集合转为了列表
print(sorted(squared))  # [1, 8, 27, 64]


# 用列表推导式重写for循环
# cz_num是集合，里面的key是“猪”之类的元素, 值value是“1”之类的数字
cz_num = {i: 0 for i in chinese_zodiac}
print(cz_num.keys())                # dict_keys(['虎', '鸡', '龙', '鼠', '牛', '蛇', '兔', '猴', '狗', '猪', '马', '羊'])
print(cz_num.values())              # dict_values([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
z_num = {i: 0 for i in zodiac_name}


# 无限循环统计输入年月日对应的生肖和星座的个数
while True:
    int_y = int(input('please input year:'))
    int_m = int(input('please input month:'))
    int_d = int(input('please input day:'))

    i = 0
    while (int_m, int_d) > zodiac_days[i]:
        if int_m == 12 and int_d >= 23:
            break
        i += 1
    print('你出生于 %s 年，生肖是 %s，星座是 %s ' % (int_y, chinese_zodiac[int_y % 12], zodiac_name[i]))

    cz_num[chinese_zodiac[int_y % 12]] += 1
    z_num[zodiac_name[i]] += 1

    for key in cz_num.keys():
        print('生肖 %s 有 %s 个' % (key, cz_num[key]))

    for key in z_num.keys():
        print('星座 %s 有 %s 个' % (key, z_num[key]))

